//### This file created by BYACC 1.8(/Java extension  1.15)
//### Java capabilities added 7 Jan 97, Bob Jamison
//### Updated : 27 Nov 97  -- Bob Jamison, Joe Nieten
//###           01 Jan 98  -- Bob Jamison -- fixed generic semantic constructor
//###           01 Jun 99  -- Bob Jamison -- added Runnable support
//###           06 Aug 00  -- Bob Jamison -- made state variables class-global
//###           03 Jan 01  -- Bob Jamison -- improved flags, tracing
//###           16 May 01  -- Bob Jamison -- added custom stack sizing
//###           04 Mar 02  -- Yuval Oren  -- improved java performance, added options
//###           14 Mar 02  -- Tomas Hurka -- -d support, static initializer workaround
//### Please send bug reports to tom@hukatronic.cz
//### static char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley) 01/20/90";






//#line 2 "yacc.txt"
package tpcompiladores;
import Ide.IDE;
import java.util.Vector;
//#line 21 "Parser.java"




public class Parser
{

boolean yydebug;        //do I want debug output?
int yynerrs;            //number of errors so far
int yyerrflag;          //was there an error?
int yychar;             //the current working character

//########## MESSAGES ##########
//###############################################################
// method: debug
//###############################################################
void debug(String msg)
{
  if (yydebug)
    System.out.println(msg);
}

//########## STATE STACK ##########
final static int YYSTACKSIZE = 500;  //maximum stack size
int statestk[] = new int[YYSTACKSIZE]; //state stack
int stateptr;
int stateptrmax;                     //highest index of stackptr
int statemax;                        //state when highest index reached
//###############################################################
// methods: state stack push,pop,drop,peek
//###############################################################
final void state_push(int state)
{
  try {
		stateptr++;
		statestk[stateptr]=state;
	 }
	 catch (ArrayIndexOutOfBoundsException e) {
     int oldsize = statestk.length;
     int newsize = oldsize * 2;
     int[] newstack = new int[newsize];
     System.arraycopy(statestk,0,newstack,0,oldsize);
     statestk = newstack;
     statestk[stateptr]=state;
  }
}
final int state_pop()
{
  return statestk[stateptr--];
}
final void state_drop(int cnt)
{
  stateptr -= cnt; 
}
final int state_peek(int relative)
{
  return statestk[stateptr-relative];
}
//###############################################################
// method: init_stacks : allocate and prepare stacks
//###############################################################
final boolean init_stacks()
{
  stateptr = -1;
  val_init();
  return true;
}
//###############################################################
// method: dump_stacks : show n levels of the stacks
//###############################################################
void dump_stacks(int count)
{
int i;
  System.out.println("=index==state====value=     s:"+stateptr+"  v:"+valptr);
  for (i=0;i<count;i++)
    System.out.println(" "+i+"    "+statestk[i]+"      "+valstk[i]);
  System.out.println("======================");
}


//########## SEMANTIC VALUES ##########
//public class ParserVal is defined in ParserVal.java


String   yytext;//user variable to return contextual strings
ParserVal yyval; //used to return semantic vals from action routines
ParserVal yylval;//the 'lval' (result) I got from yylex()
ParserVal valstk[];
int valptr;
//###############################################################
// methods: value stack push,pop,drop,peek.
//###############################################################
void val_init()
{
  valstk=new ParserVal[YYSTACKSIZE];
  yyval=new ParserVal();
  yylval=new ParserVal();
  valptr=-1;
}
void val_push(ParserVal val)
{
  if (valptr>=YYSTACKSIZE)
    return;
  valstk[++valptr]=val;
}
ParserVal val_pop()
{
  if (valptr<0)
    return new ParserVal();
  return valstk[valptr--];
}
void val_drop(int cnt)
{
int ptr;
  ptr=valptr-cnt;
  if (ptr<0)
    return;
  valptr = ptr;
}
ParserVal val_peek(int relative)
{
int ptr;
  ptr=valptr-relative;
  if (ptr<0)
    return new ParserVal();
  return valstk[ptr];
}
final ParserVal dup_yyval(ParserVal val)
{
  ParserVal dup = new ParserVal();
  dup.ival = val.ival;
  dup.dval = val.dval;
  dup.sval = val.sval;
  dup.obj = val.obj;
  return dup;
}
//#### end semantic value section ####
public final static short IF=257;
public final static short THEN=258;
public final static short ELSE=259;
public final static short PRINT=260;
public final static short VAR=261;
public final static short ARRAY=262;
public final static short DOUBLE=263;
public final static short DO=264;
public final static short UNTIL=265;
public final static short ASIG=266;
public final static short MAYI=267;
public final static short MAY=268;
public final static short DIST=269;
public final static short MENI=270;
public final static short MEN=271;
public final static short IDENTIFICADOR=272;
public final static short DOUB=273;
public final static short CADENA=274;
public final static short PREC_THEN=275;
public final static short YYERRCODE=256;
final static short yylhs[] = {                           -1,
    0,    0,    1,    1,    1,    1,    2,    2,    2,    2,
    2,    2,    2,    2,    2,    2,    6,    6,    7,    8,
    9,    9,    5,    5,    5,    5,    5,   11,   10,   10,
   10,   10,   10,   10,   10,    4,    4,    4,    3,    3,
    3,    3,   15,   15,   15,   16,   16,   16,   16,   16,
   16,   14,   14,   14,   14,   14,   17,   17,   17,   17,
   17,   13,   13,   12,   12,   12,   12,
};
final static short yylen[] = {                            2,
    1,    1,    2,    2,    1,    1,    2,    1,    1,    5,
    2,    2,    5,    4,    3,    2,    2,    4,    5,    1,
    3,    1,    6,    6,    5,    4,    2,    1,    3,    3,
    3,    3,    3,    4,    2,    3,    3,    2,    2,    2,
    2,    2,    2,    3,    3,    5,    4,    3,    2,    6,
    6,    3,    3,    3,    3,    1,    3,    3,    3,    3,
    1,    1,    4,    1,    1,    2,    4,
};
final static short yydefred[] = {                         0,
    2,    0,    0,    0,    0,   28,    0,    0,    1,    0,
    0,    0,    0,    9,    0,    0,    0,    0,   16,    0,
   42,    0,   41,   40,    0,   39,    0,    3,    4,   11,
    7,   12,    0,   22,    0,   20,   27,    0,   38,    0,
    0,   65,    0,    0,    0,   15,    0,   49,    0,   43,
    0,    0,    0,    0,    0,   37,   61,    0,    0,    0,
   66,    0,   35,    0,    0,    0,    0,    0,    0,   14,
    0,   48,    0,   45,   44,   63,   21,   18,   26,    0,
    0,    0,    0,    0,    0,   19,   32,   30,   33,   31,
   29,    0,   13,   10,   47,    0,   25,    0,   54,    0,
   55,    0,   59,   57,   60,   58,   67,   34,   46,    0,
   24,   23,   51,   50,
};
final static short yydgoto[] = {                          8,
    9,   10,   11,   12,   13,   14,   15,   35,   36,   44,
   16,   57,   17,   58,   26,   23,   59,
};
final static short yysindex[] = {                      -191,
    0,   17,  -40, -213, -209,    0,  -59,    0,    0, -175,
 -175,  -33, -196,    0,  -96, -102, -211,  -28,    0, -212,
    0,  -72,    0,    0,   42,    0,  -28,    0,    0,    0,
    0,    0, -175,    0, -195,    0,    0, -173,    0,  -38,
   14,    0, -170,   63,   22,    0,  -31,    0, -225,    0,
 -188,   15,  -18,  -96,  -35,    0,    0,   53,   11,  -28,
    0, -149,    0,  -28,  -28,  -28,  -28,  -28,   49,    0,
   -8,    0,  -70,    0,    0,    0,    0,    0,    0,  -36,
  -34,  -32,  -30,   -5,   19,    0,    0,    0,    0,    0,
    0,  -28,    0,    0,    0,   47,    0,  -23,    0,   11,
    0,   11,    0,    0,    0,    0,    0,    0,    0, -177,
    0,    0,    0,    0,
};
final static short yyrindex[] = {                         0,
    0,    0,    0,    0,    0,    0, -210,    0,    0,   24,
   25,    0,    1,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,   12,    0,    0,    0,    0,    0,
  -39,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,   -7,  -29,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,  -10,
    0,   -9,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,
};
final static short yygindex[] = {                         0,
   28,   26,    0,    0,    0,    0,    0,    0,   13,   31,
    0,   10,    0,    0,   62,    4,   18,
};
final static int YYTABLESIZE=293;
static short yytable[];
static { yytable();}
static void yytable(){
yytable = new short[]{                         20,
    8,   64,   64,   64,   80,   64,   43,   64,   43,   71,
   43,   17,   43,   56,   43,   56,   43,  112,   49,   64,
   33,   64,   96,    5,    6,   31,   33,   45,   38,   56,
   72,   27,   52,   53,   52,   53,   52,   28,   29,   43,
   34,   34,   21,   46,   39,   62,   24,   73,   52,   53,
   94,   36,   83,   64,   40,   62,   18,   84,   22,   32,
   53,   47,   25,   54,    1,    2,   78,   74,    3,   85,
    4,    5,    6,   87,   88,   89,   90,   91,  113,   34,
    7,    2,   69,   25,    3,   51,    4,    5,    6,   45,
  110,   55,  104,  106,   22,   81,    7,   82,  100,  102,
   50,  108,   61,   62,   60,  109,   77,   76,   86,   92,
   98,  107,   75,  114,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    8,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,   17,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    5,    6,
    0,    0,    0,   37,    2,    0,    0,    3,    0,    0,
    2,    6,    0,    3,    0,    0,    0,    6,    0,    7,
    0,    0,    0,    0,    0,    7,    0,    0,    0,    0,
    0,    0,    0,   48,    0,   95,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,   19,   64,   56,    0,   97,
   79,   99,   30,  101,   70,  103,   56,   64,   64,   64,
   64,   64,  111,   41,   42,   41,   42,   41,   42,   41,
   42,   41,   42,   41,   42,   52,   53,   93,   36,    0,
  105,    0,    0,    0,    0,    0,    0,    8,    0,    8,
    8,    0,    8,    8,    8,    8,   41,   42,   17,    0,
    0,   17,    8,   17,   17,   17,   17,   63,    0,    0,
    0,    0,    0,   17,    0,    0,    0,    0,   64,   65,
   66,   67,   68,
};
}
static short yycheck[];
static { yycheck(); }
static void yycheck() {
yycheck = new short[] {                         40,
    0,   41,   42,   43,   40,   45,   45,   47,   45,   41,
   45,    0,   45,   43,   45,   45,   45,   41,   91,   59,
  123,   61,   93,    0,    0,   59,  123,   18,   16,   59,
  256,   91,   43,   43,   45,   45,   27,   10,   11,   45,
   15,   16,  256,  256,  256,  256,  256,  273,   59,   59,
   59,   59,   42,   93,  266,  266,   40,   47,  272,  256,
   33,  274,  272,  259,  256,  257,   54,  256,  260,   60,
  262,  263,  264,   64,   65,   66,   67,   68,  256,   54,
  272,  257,   61,  272,  260,   44,  262,  263,  264,   80,
   44,  265,   83,   84,  272,   43,  272,   45,   81,   82,
   59,   92,  273,   41,   91,   59,  125,   93,  258,   61,
   80,   93,   51,  110,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,  125,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,  125,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  125,  125,
   -1,   -1,   -1,  256,  257,   -1,   -1,  260,   -1,   -1,
  257,  264,   -1,  260,   -1,   -1,   -1,  264,   -1,  272,
   -1,   -1,   -1,   -1,   -1,  272,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,  256,   -1,  256,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,  256,  256,  256,   -1,  256,
  256,  256,  256,  256,  256,  256,  256,  267,  268,  269,
  270,  271,  256,  272,  273,  272,  273,  272,  273,  272,
  273,  272,  273,  272,  273,  256,  256,  256,  256,   -1,
  256,   -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,  259,
  260,   -1,  262,  263,  264,  265,  272,  273,  257,   -1,
   -1,  260,  272,  262,  263,  264,  265,  256,   -1,   -1,
   -1,   -1,   -1,  272,   -1,   -1,   -1,   -1,  267,  268,
  269,  270,  271,
};
}
final static short YYFINAL=8;
final static short YYMAXTOKEN=275;
final static String yyname[] = {
"end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,"'('","')'","'*'","'+'","','",
"'-'",null,"'/'",null,null,null,null,null,null,null,null,null,null,null,"';'",
null,"'='",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
"'['",null,"']'",null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,"'{'",null,"'}'",null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,"IF","THEN","ELSE","PRINT","VAR",
"ARRAY","DOUBLE","DO","UNTIL","ASIG","MAYI","MAY","DIST","MENI","MEN",
"IDENTIFICADOR","DOUB","CADENA","PREC_THEN",
};
final static String yyrule[] = {
"$accept : PROGRAMA",
"PROGRAMA : SENTENCIAS",
"PROGRAMA : error",
"SENTENCIAS : SENT SENTENCIAS",
"SENTENCIAS : DECLARACION SENTENCIAS",
"SENTENCIAS : SENT",
"SENTENCIAS : DECLARACION",
"SENT : ASIGNACION ';'",
"SENT : ITERACION",
"SENT : SELECCION",
"SENT : PRINT '(' CADENA ')' ';'",
"SENT : ASIGNACION error",
"SENT : ITERACION error",
"SENT : PRINT '(' CADENA ')' error",
"SENT : PRINT '(' CADENA error",
"SENT : PRINT '(' error",
"SENT : PRINT error",
"SELECCION : BLOQUE_IF BLOQUE_THEN",
"SELECCION : BLOQUE_IF BLOQUE_THEN ELSE BLOQUE",
"BLOQUE_IF : IF '(' COND ')' THEN",
"BLOQUE_THEN : BLOQUE",
"BLOQUE : '{' SENTENCIAS '}'",
"BLOQUE : SENT",
"ITERACION : ITER_DO BLOQUE UNTIL '(' COND ')'",
"ITERACION : ITER_DO BLOQUE UNTIL '(' COND error",
"ITERACION : ITER_DO BLOQUE UNTIL '(' error",
"ITERACION : ITER_DO BLOQUE UNTIL error",
"ITERACION : ITER_DO error",
"ITER_DO : DO",
"COND : FACTOR MEN FACTOR",
"COND : FACTOR MAY FACTOR",
"COND : FACTOR MENI FACTOR",
"COND : FACTOR MAYI FACTOR",
"COND : FACTOR DIST FACTOR",
"COND : FACTOR '=' '=' FACTOR",
"COND : FACTOR error",
"ASIGNACION : ID ASIG EXARIT",
"ASIGNACION : ID ASIG error",
"ASIGNACION : ID error",
"DECLARACION : DOUBLE LISTA1",
"DECLARACION : DOUBLE error",
"DECLARACION : ARRAY LISTA2",
"DECLARACION : ARRAY error",
"LISTA1 : IDENTIFICADOR ';'",
"LISTA1 : IDENTIFICADOR ',' LISTA1",
"LISTA1 : IDENTIFICADOR ',' error",
"LISTA2 : IDENTIFICADOR '[' DOUB ']' ';'",
"LISTA2 : IDENTIFICADOR '[' DOUB error",
"LISTA2 : IDENTIFICADOR '[' error",
"LISTA2 : IDENTIFICADOR error",
"LISTA2 : IDENTIFICADOR '[' DOUB ']' ',' LISTA2",
"LISTA2 : IDENTIFICADOR '[' DOUB ']' ',' error",
"EXARIT : EXARIT '+' TERMINO",
"EXARIT : EXARIT '-' TERMINO",
"EXARIT : EXARIT '+' error",
"EXARIT : EXARIT '-' error",
"EXARIT : TERMINO",
"TERMINO : TERMINO '*' FACTOR",
"TERMINO : TERMINO '/' FACTOR",
"TERMINO : TERMINO '*' error",
"TERMINO : TERMINO '/' error",
"TERMINO : FACTOR",
"ID : IDENTIFICADOR",
"ID : IDENTIFICADOR '[' FACTOR ']'",
"FACTOR : IDENTIFICADOR",
"FACTOR : DOUB",
"FACTOR : '-' DOUB",
"FACTOR : IDENTIFICADOR '[' FACTOR ']'",
};

//#line 192 "yacc.txt"

private Lexico lex;
private IDE frame;
private Vector<Token> tokens;
private PolacaInversa polaca;
private TablaSimb tabla;

    public void yyerror (String msg){
        polaca.setError();
        frame.appendConsole("Sintactico: Linea " + lex.getLineNumber() + ":    " + msg );
        
    }

    public Vector<Token> getTokens(){
        return tokens;
	}	


    public int yylex () {
        Token t = lex.getToken();
	frame.addToken(t);
	if (t.getKey() != null)
	    yylval = new ParserVal(t.getKey());
	else 
            yylval = new ParserVal();
        return t.getId();
    }

    public Parser(Lexico lex, IDE frame, PolacaInversa polaca) {
        this.lex = lex;
	this.frame = frame;
        this.polaca = polaca;
        this.tabla = lex.getTable();
    }


//#line 382 "Parser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
void yylexdebug(int state,int ch)
{
String s=null;
  if (ch < 0) ch=0;
  if (ch <= YYMAXTOKEN) //check index bounds
     s = yyname[ch];    //now get it
  if (s==null)
    s = "illegal-symbol";
  debug("state "+state+", reading "+ch+" ("+s+")");
}





//The following are now global, to aid in error reporting
int yyn;       //next next thing to do
int yym;       //
int yystate;   //current parsing state from state table
String yys;    //current token string


//###############################################################
// method: yyparse : parse input and execute indicated items
//###############################################################
public int yyparse()
{
boolean doaction;
  init_stacks();
  yynerrs = 0;
  yyerrflag = 0;
  yychar = -1;          //impossible char forces a read
  yystate=0;            //initial state
  state_push(yystate);  //save it
  val_push(yylval);     //save empty value
  while (true) //until parsing is done, either correctly, or w/error
    {
    doaction=true;
    if (yydebug) debug("loop"); 
    //#### NEXT ACTION (from reduction table)
    for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
      {
      if (yydebug) debug("yyn:"+yyn+"  state:"+yystate+"  yychar:"+yychar);
      if (yychar < 0)      //we want a char?
        {
        yychar = yylex();  //get next token
        if (yydebug) debug(" next yychar:"+yychar);
        //#### ERROR CHECK ####
        if (yychar < 0)    //it it didn't work/error
          {
          yychar = 0;      //change it to default string (no -1!)
          if (yydebug)
            yylexdebug(yystate,yychar);
          }
        }//yychar<0
      yyn = yysindex[yystate];  //get amount to shift by (shift index)
      if ((yyn != 0) && (yyn += yychar) >= 0 &&
          yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
        {
        if (yydebug)
          debug("state "+yystate+", shifting to state "+yytable[yyn]);
        //#### NEXT STATE ####
        yystate = yytable[yyn];//we are in a new state
        state_push(yystate);   //save it
        val_push(yylval);      //push our lval as the input for next rule
        yychar = -1;           //since we have 'eaten' a token, say we need another
        if (yyerrflag > 0)     //have we recovered an error?
           --yyerrflag;        //give ourselves credit
        doaction=false;        //but don't process yet
        break;   //quit the yyn=0 loop
        }

    yyn = yyrindex[yystate];  //reduce
    if ((yyn !=0 ) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
      {   //we reduced!
      if (yydebug) debug("reduce");
      yyn = yytable[yyn];
      doaction=true; //get ready to execute
      break;         //drop down to actions
      }
    else //ERROR RECOVERY
      {
      if (yyerrflag==0)
        {
        yyerror("syntax error");
        yynerrs++;
        }
      if (yyerrflag < 3) //low error count?
        {
        yyerrflag = 3;
        while (true)   //do until break
          {
          if (stateptr<0)   //check for under & overflow here
            {
            yyerror("stack underflow. aborting...");  //note lower case 's'
            return 1;
            }
          yyn = yysindex[state_peek(0)];
          if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
            if (yydebug)
              debug("state "+state_peek(0)+", error recovery shifting to state "+yytable[yyn]+" ");
            yystate = yytable[yyn];
            state_push(yystate);
            val_push(yylval);
            doaction=false;
            break;
            }
          else
            {
            if (yydebug)
              debug("error recovery discarding state "+state_peek(0)+" ");
            if (stateptr<0)   //check for under & overflow here
              {
              yyerror("Stack underflow. aborting...");  //capital 'S'
              return 1;
              }
            state_pop();
            val_pop();
            }
          }
        }
      else            //discard this token
        {
        if (yychar == 0)
          return 1; //yyabort
        if (yydebug)
          {
          yys = null;
          if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
          if (yys == null) yys = "illegal-symbol";
          debug("state "+yystate+", error recovery discards token "+yychar+" ("+yys+")");
          }
        yychar = -1;  //read another
        }
      }//end error recovery
    }//yyn=0 loop
    if (!doaction)   //any reason not to proceed?
      continue;      //skip action
    yym = yylen[yyn];          //get count of terminals on rhs
    if (yydebug)
      debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
    if (yym>0)                 //if count of rhs not 'nil'
      yyval = val_peek(yym-1); //get current semantic value
    yyval = dup_yyval(yyval); //duplicate yyval if ParserVal is used as semantic value
    switch(yyn)
      {
//########## USER-SUPPLIED ACTIONS ##########
case 7:
//#line 28 "yacc.txt"
{frame.addSinStruct("ASIGNACION"); }
break;
case 8:
//#line 29 "yacc.txt"
{ frame.addSinStruct("DO-UNTIL"); }
break;
case 10:
//#line 31 "yacc.txt"
{polaca.apilar("PRINT: " + val_peek(2).sval);frame.addSinStruct("PRINT"); }
break;
case 11:
//#line 32 "yacc.txt"
{ yyerror("; Expected"); }
break;
case 12:
//#line 33 "yacc.txt"
{ yyerror("; Expected"); }
break;
case 13:
//#line 34 "yacc.txt"
{ yyerror("; Expected"); }
break;
case 14:
//#line 35 "yacc.txt"
{ yyerror(") Expected"); }
break;
case 15:
//#line 36 "yacc.txt"
{ yyerror("LINE Expected"); }
break;
case 16:
//#line 37 "yacc.txt"
{ yyerror("( Expected"); }
break;
case 17:
//#line 40 "yacc.txt"
{ polaca.completar(polaca.desapilarPila());frame.addSinStruct("IF"); }
break;
case 18:
//#line 41 "yacc.txt"
{ polaca.completar(polaca.desapilarPila());frame.addSinStruct("IF-THEN-ELSE"); }
break;
case 19:
//#line 44 "yacc.txt"
{
                                  polaca.apilarPila();
                                  }
break;
case 20:
//#line 49 "yacc.txt"
{polaca.apilar("");
                     polaca.apilar("JMP");
                     polaca.completar(polaca.desapilarPila());
                     polaca.apilarPila();
                    }
break;
case 23:
//#line 60 "yacc.txt"
{
                                               polaca.completar(polaca.desapilarPila(),polaca.getTam());
                     }
break;
case 24:
//#line 63 "yacc.txt"
{ yyerror(") Expected");}
break;
case 25:
//#line 64 "yacc.txt"
{ yyerror("COND Expected");}
break;
case 26:
//#line 65 "yacc.txt"
{ yyerror("(COND) Expected");}
break;
case 27:
//#line 66 "yacc.txt"
{ yyerror("DO-UNTIL Invalid Format");}
break;
case 28:
//#line 69 "yacc.txt"
{polaca.apilarPila();polaca.apilar("DO");}
break;
case 29:
//#line 73 "yacc.txt"
{polaca.apilar("<");polaca.apilar("");polaca.apilar("JAE");}
break;
case 30:
//#line 74 "yacc.txt"
{polaca.apilar(">");polaca.apilar("");polaca.apilar("JBE");}
break;
case 31:
//#line 75 "yacc.txt"
{polaca.apilar("<=");polaca.apilar("");polaca.apilar("JA");}
break;
case 32:
//#line 76 "yacc.txt"
{polaca.apilar(">=");polaca.apilar("");polaca.apilar("JB");}
break;
case 33:
//#line 77 "yacc.txt"
{polaca.apilar("<>");polaca.apilar("");polaca.apilar("JE");}
break;
case 34:
//#line 78 "yacc.txt"
{polaca.apilar("==");polaca.apilar("");polaca.apilar("JNE");}
break;
case 35:
//#line 79 "yacc.txt"
{ yyerror("COMPARATOR EXPECTED");}
break;
case 36:
//#line 82 "yacc.txt"
{polaca.apilar(":=");}
break;
case 37:
//#line 83 "yacc.txt"
{ yyerror("VALUE Expected");}
break;
case 38:
//#line 84 "yacc.txt"
{ yyerror("ASIGNATION Invalid Format");}
break;
case 39:
//#line 87 "yacc.txt"
{frame.addSinStruct("DECLARACION");}
break;
case 40:
//#line 88 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 41:
//#line 89 "yacc.txt"
{frame.addSinStruct("DECLARACION");}
break;
case 42:
//#line 90 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 43:
//#line 93 "yacc.txt"
{if(!tabla.exists("_"+val_peek(1).sval))
                                tabla.putSymbol("_"+val_peek(1).sval,new RegTs("DOUBLE",""));
                            else{yyerror("Variable " + val_peek(1).sval + " ya declarada anteriormente");}    }
break;
case 44:
//#line 96 "yacc.txt"
{if(!tabla.exists("_"+val_peek(2).sval)){
                                    tabla.putSymbol("_"+val_peek(2).sval,new RegTs("DOUBLE",""));}
                                  else{yyerror("Variable " + val_peek(2).sval + " ya declarada anteriormente");}}
break;
case 45:
//#line 99 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 46:
//#line 102 "yacc.txt"
{if(Double.parseDouble(val_peek(2).sval) < 1)
                                            yyerror("El indice debe ser >=1");
                                       else{
                                        if(!tabla.exists("_"+val_peek(4).sval)){
                                            tabla.putSymbol("_"+val_peek(4).sval,new RegTs("ARRAY"  + " Lim Superior: " + val_peek(2).sval,""));}
                                            else{yyerror("Variable " + val_peek(4).sval + " ya declarada anteriormente");}    
                                    }
        }
break;
case 47:
//#line 110 "yacc.txt"
{ yyerror("] Expected");}
break;
case 48:
//#line 111 "yacc.txt"
{ yyerror("DOUBLE Expected");}
break;
case 49:
//#line 112 "yacc.txt"
{ yyerror("[double] Expected");}
break;
case 50:
//#line 113 "yacc.txt"
{if(!tabla.exists("_"+val_peek(5).sval)){
                                            tabla.putSymbol("_"+val_peek(5).sval,new RegTs("ARRAY"  + " Lim Superior: " + val_peek(3).sval,""));}
                                            else{yyerror("Variable " + val_peek(5).sval + " ya declarada anteriormente");} }
break;
case 51:
//#line 116 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 52:
//#line 120 "yacc.txt"
{polaca.apilar("+");}
break;
case 53:
//#line 121 "yacc.txt"
{polaca.apilar("-");}
break;
case 54:
//#line 122 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 55:
//#line 123 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 57:
//#line 127 "yacc.txt"
{polaca.apilar("*");}
break;
case 58:
//#line 128 "yacc.txt"
{polaca.apilar("/");}
break;
case 59:
//#line 129 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 60:
//#line 130 "yacc.txt"
{ yyerror("IDENTIFIER Expected");}
break;
case 62:
//#line 134 "yacc.txt"
{ polaca.apilar(val_peek(0).sval);
                     if(!tabla.exists("_"+val_peek(0).sval)){
                        yyerror("Variable " + val_peek(0).sval + " no declarada anteriormente");
                      }
                    }
break;
case 63:
//#line 139 "yacc.txt"
{if((tabla.isArray("_"+val_peek(3).sval) && (!tabla.isVar("_"+val_peek(1).sval)))){
                                    Double pos = Math.floor(Double.parseDouble(val_peek(1).sval));
                                    if((1<=pos) && (pos<=Double.parseDouble(tabla.getLim("_"+val_peek(3).sval)))){
                                        Integer dir = (pos.intValue()-1) * 8;
                                        polaca.desapilarPolaca(polaca.getTam()-1);
                                        polaca.apilar("ARRAY,"+val_peek(3).sval+","+val_peek(1).sval+"," + dir);                                
                                    }
                                    else{
                                        yyerror("Error de limites de array");
                                    }
                                 }
                                 else{
                                        yyerror("Error de tipo");
                                    }   
}
break;
case 64:
//#line 156 "yacc.txt"
{yyval.sval = val_peek(0).sval;polaca.apilar(val_peek(0).sval);
                       if(!tabla.exists("_"+val_peek(0).sval))
                         yyerror("Variable " + val_peek(0).sval + " no declarada anteriormente");}
break;
case 65:
//#line 159 "yacc.txt"
{yyval.sval = val_peek(0).sval;polaca.apilar(val_peek(0).sval);}
break;
case 66:
//#line 160 "yacc.txt"
{lex.getTable().negativo(val_peek(0).sval);polaca.apilar("-" + val_peek(0).sval);}
break;
case 67:
//#line 161 "yacc.txt"
{ if(tabla.isArray("_"+val_peek(3).sval)){
                                            polaca.desapilarPolaca(polaca.getTam()-1);
                                            polaca.apilar("1.");
                                            polaca.apilar(val_peek(1).sval);
                                            polaca.apilar(">");
                                            polaca.apilar("");
                                            polaca.apilar("JBE");
                                            polaca.apilarPila();
                                            polaca.apilar("ABORT");
                                            polaca.completar(polaca.desapilarPila());
                                            polaca.apilar(val_peek(1).sval);
                                            polaca.apilar(tabla.getLim("_"+val_peek(3).sval));
                                            polaca.apilar(">");
                                            polaca.apilar("");
                                            polaca.apilar("JBE");
                                            polaca.apilarPila();
                                            polaca.apilar("ABORT");
                                            polaca.completar(polaca.desapilarPila());
                                            Double pos = Math.floor(Double.parseDouble(val_peek(1).sval));
                                            Integer dir = (pos.intValue()-1) * 8;
                                            polaca.apilar("ARRAY,"+val_peek(3).sval+","+val_peek(1).sval+","+dir);                                                  
                                       }
                                       else{
                                            yyerror("Error de tipo");            
                                        }                                        

}
break;
//#line 822 "Parser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
    }//switch
    //#### Now let's reduce... ####
    if (yydebug) debug("reduce");
    state_drop(yym);             //we just reduced yylen states
    yystate = state_peek(0);     //get new state
    val_drop(yym);               //corresponding value drop
    yym = yylhs[yyn];            //select next TERMINAL(on lhs)
    if (yystate == 0 && yym == 0)//done? 'rest' state and at first TERMINAL
      {
      if (yydebug) debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
      yystate = YYFINAL;         //explicitly say we're done
      state_push(YYFINAL);       //and save it
      val_push(yyval);           //also save the semantic value of parsing
      if (yychar < 0)            //we want another character?
        {
        yychar = yylex();        //get next character
        if (yychar<0) yychar=0;  //clean, if necessary
        if (yydebug)
          yylexdebug(yystate,yychar);
        }
      if (yychar == 0)          //Good exit (if lex returns 0 ;-)
         break;                 //quit the loop--all DONE
      }//if yystate
    else                        //else not done yet
      {                         //get next state and push, for next yydefred[]
      yyn = yygindex[yym];      //find out where to go
      if ((yyn != 0) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn]; //get new state
      else
        yystate = yydgoto[yym]; //else go to new defred
      if (yydebug) debug("after reduction, shifting from state "+state_peek(0)+" to state "+yystate+"");
      state_push(yystate);     //going again, so push state & val...
      val_push(yyval);         //for next action
      }
    }//main loop
  return 0;//yyaccept!!
}
//## end of method parse() ######################################



//## run() --- for Thread #######################################
/**
 * A default run method, used for operating this parser
 * object in the background.  It is intended for extending Thread
 * or implementing Runnable.  Turn off with -Jnorun .
 */
public void run()
{
  yyparse();
}
//## end of method run() ########################################



//## Constructors ###############################################
/**
 * Default constructor.  Turn off with -Jnoconstruct .

 */
public Parser()
{
  //nothing to do
}


/**
 * Create a parser, setting the debug to true or false.
 * @param debugMe true for debugging, false for no debug.
 */
public Parser(boolean debugMe)
{
  yydebug=debugMe;
}
//###############################################################



}
//################### END OF CLASS ##############################
